Properties and methods of HTML tag objects

Every HTML tag is represented by a JavaScript object. Tags are organized in a tree hierarchy, where tag x is a parent of tag y if y falls completely within x's opening and closing tags (<x>x content surrounding <y>y content</y></x>). The following table lists the properties and methods of tag objects in Dreamweaver, along with their return values (with explanations, where appropriate). A bullet (·) marks read-only properties.

Property or method Return value and explanation

nodeType ·

Node.ELEMENT_NODE

parentNode ·

The parent tag. If this is the HTML tag, then the document object is returned instead.

childNodes ·

A nodelist containing all the immediate children of the tag.

tagName ·

The HTML name for the tag, such as IMG, A, or BLINK. This value is always returned in uppercase letters.

attrName

A string containing the value of the specified tag attribute. tag.attrName cannot be used if attrName is a reserved word in the JavaScript language (for example, class). In this case, use getAttribute() and setAttribute() instead.

innerHTML

The HTML source contained between the begin tag and the end tag. For example, in the code <p><b>Hello</b>, World!</p>, p.innerHTML would return <b>Hello</b>, World!. If you write to this property, the DOM tree is immediately updated to reflect the new structure of the document. (This property is not included in DOM Level 1; however, it is supported by IE 4.0.)

outerHTML

The HTML source for this tag, including the tag itself. For the example code above, p.outerHTML would return <p><b>Hello</b>, World!</p>. If you write to this property, the DOM tree is immediately updated to reflect the new structure of the document. (This property is not included in DOM Level 1; however, it is supported by IE 4.0.)

getAttribute(attrName)

The value of the specified attribute if it is explicitly specified; otherwise, null.

getTranslatedAttribute(attrName)

The translated value of the specified attribute, or the same value tha would be returned by getAttribute() if the attribute's value is not translated. (This property is not included in DOM Level 1; it was added to Dreamweaver 3 to support attribute translation.)

setAttribute(attrName, attrValue)

No return value. Sets the specified attribute to the specified value: for example, img.setAttribute("src", "image/roses.gif").

removeAttribute(attrName)

No return value. Removes the specified attribute and its value from the HTML for this tag.

getElementsByTagName(tagName)

A nodelist that can be used to step through child tags of type tagName (for example, IMG, DIV, and so on).

If the tag argument is LAYER, the function returns all LAYER and ILAYER tags and all absolutely positioned DIV and SPAN tags.

If the tag argument is INPUT, the function returns all form elements. (For this shortcut to work properly, all form field names must begin with a letter.)

hasChildNodes()

A Boolean value indicating whether the tag has any children.

hasTranslatedAttributes()

A Boolean value indicating whether the tag has any translated attributes. (This property is not included in DOM Level 1; it was added to Dreamweaver 3 to support attribute translation.)